I wrote this Application about a year ago to quickly test changes to the Unicode Converter. Later, I put in support for the Text Encoding Converter but it is minimal. UnicodeHub show cases the Unicode Converter. It will use the Unicode Converter whenever possible even if the Text Encoding Converter can handle the same conversion.
The application is written using PowerPlant. I needed a way to get a decent User Interface going as quickly as possible and PowerPlant provided a great framework. Please ignore the PowerPlant code itself. I do not pretend to be a good PP code programmer so please ignore it. If you wish to make suggestions or changes to the code to enhance it, please send me those comments and I'll implement them.
The code is in two files: UnicodeHub.cp and Convert.cp. Most of the interesting bits are in Convert.cp. However, UnicodeHub.cp does have some important TEC usage tips in it.
While looking at the code search for the following:
TEC SPECIFIC CODE COMMENT
You'll find comments related to using the converter.
What can you expect to learn from UnicodeHub?
This application exercises almost every feature of the Unicode Converter. It does not use the Truncate APIs or the offset parameters in the Convert calls. What it shows you is:
* Getting a list of all the available encodings and its names
* Converting from Text Edit Styled text to Unicode and back
- This shows you how to go from the world of Script Codes to Text Encodings
* Use of the CJK language hint corporate characters
* How to determine if an encoding is Unicode
* Use of standard or UTF-8 formatted Unicode
* Simple use of the Text Encoding Converter
- Converting Text
- Flushing internal buffers
* Unicode conversion flag usage
* Output buffer allocation
- Minumum buffer sizes
- How to handle errors dealing with output buffers being too small
How to use the UnicodeHub?
First and foremost, if you want to see the nice features of UnicodeHub, install multiple Language Kits into your machine. However, it is not required to have any Language Kits installed.
The App displays a window with two places to enter text. On top of each of the text field, you can specify the encoding for the text you are entering and for the text that will be converted. The first one is "Styled Text". If you select this, you can only perform conversions to Unicode. Otherwise, UnicodeHub will complain.
Anytime you convert something to Unicode, the output will be in Hex. The reason is simple. We have no way to render that Unicode stream. That is why the Text Encoding Converter is here. If you convert styled text to Unicode, the Unicode output stream will show you how the different MacEncodings match the Unicode stream. This is done by switching each run from blue to red.
Converting a Unicode stream to styled text also works. Make sure that you select the Text Run and Keep Same Encoding check box. Otherwise, your text might not convert. When the conversion takes place, it selects the preferred Application Font for the target script. So, don't alarm yourself if your text does not have the original font that you started with. However, the text must be identical to whatever you started with.
Whenever you convert something, UnicodeHub will try to find a font that can render the output Text Encoding. If it cannot, then it will select the default Application font and set the typeface of the font to bold.
How do you build UnicodeHub?
Tools Required:
TEC 1.3 SDK or newer
CodeWarrior Pro 2.1
Modifications to the project required:
Add a system path to the interfaces provided by the SDK. Make sure that they precede the interfaces from Code Warrior.
Add a user path to the Stub Libraries folder in the SDK.